package org.swingDemo.fileFilter;

import cn.hutool.core.io.FileUtil;
import org.swingDemo.helper.ClassifyOptionHelper;

import java.io.File;
import java.io.FileFilter;

public class ClassifyFileFilter implements FileFilter {

    @Override
    public boolean accept(File file) {
        File parentFile = FileUtil.getParent(file, 1);
        String parentFilePath = FileUtil.getAbsolutePath(parentFile);
        String fileExtName = FileUtil.extName(file);

        if (!ClassifyOptionHelper.isRecursiveSubDir()
                && !ClassifyOptionHelper.getSourcePath().equals(parentFilePath)) {
            return false;
        }

        if (!ClassifyOptionHelper.getFileExtension().contains("*") &&
                !ClassifyOptionHelper.getFileExtension().contains(fileExtName)) {
            return false;
        }
        return true;
    }
}
